<template>
  <div class="payment-info">
    <div class="title">广工清远校友会</div>
    <img class="content-img" src="./img.png" alt="">
    <div class="sub-title">活动金额</div>
    <div class="price">{{ cost }} 元</div>
    <van-button
      class="btn"
      block
      type="info"
      native-type="submit"
      :disabled="disable"
      @click="WxPay"
    >确定参加</van-button>
  </div>
</template>
<script>
import { GetActivityDetails } from '../../api/index'
export default {
  data() {
    return {
      cost: 0,
      disable: false
    }
  },
  async mounted() {
    const { activityId } = this.$route.query
    const { data } = await GetActivityDetails(activityId)
    const d = data.data
    if (!d) {
      this.$toast(data.msg)
      this.disable = true
      return
    }
    this.cost = data && data.data && data.data.moneyCost
    const isApply = data && data.data && data.data.isApply
    if (isApply) {
      window.location.href = `/nanc-h5/activityInfo?activityId=${activityId}&isPay=true`
    }
  },
  methods: {
    async WxPay() {
      const { activityId } = this.$route.query
      // 参数说明  第一个是活动id  第二个是支付成功之后触发的函数
      this.$WechatPayActivity(activityId, () => {
        console.log(1, '购买成功')
        window.location.href = `/nanc-h5/activityInfo?activityId=${activityId}&isPay=true`
      })
    }
  }
}
</script>

<style scoped>
.payment-info {
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #333;
  padding-bottom: 32px;
  text-align: center;
  background: #fff;
}
.title {
  font-size: 20px;
  font-family: PingFangSC-Medium, PingFang SC;
  line-height: 20px;
  padding: 32px 0;
}
.content-img {
  width: 115px;
  height: 115px;
  margin: 0 auto;
}
.sub-title {
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.9);
  margin: 20px auto 10px;
}
.price {
  font-size: 24px;
  font-family: PingFangSC-Semibold;
  font-weight: 600;
  color: #000;
  line-height: 33px;
  margin-bottom: 26px;
}
.btn {
  width: 86.5%;
  height: 45px;
  text-align: center;
  margin: 0 auto;
  border-radius: 4px;
  font-size: 16px;
}
</style>
